Wagtail Django-form編輯現有對象 (Wagtail Django-form edit existing object)


問題描述

Wagtail Django‑form編輯現有對象 (Wagtail Django‑form edit existing object)

我正在按照 GitHub 上的 wagtail‑form‑example 將 Django 表單實現到 wagtail 中。除了能夠編輯現有提交之外,我已經完成了所有工作。

這是我到目前為止所遵循的代碼 https://github.com/gasman/wagtail‑form‑example/blob/master/flavours/models.py

我嘗試了以下幾種變體代碼。

def serve(request, id):
   instance = get_object_or_404(MyModel, id=id)
   form = MyForm(request.POST or None, instance=instance)

如果有幫助,我會收到以下消息:int() 參數必須是字符串、類似字節的對像或數字,而不是“builtin_function_or_method”

任何幫助/示例將不勝感激:)


參考解法

方法 1:

Changing def serve(self, request): to def serve(request, id): doesn't work that way.

Your second argument id now holds the request object and not the expected int like the error tells you.

Start by respecting the method arguments serve(self, request). That means you need to query your form in some other way.

Eg: get_object_or_404(MyModel, id=[some hardcoded id])

If you want any form to be shown as child of your page, you could use RoutablePageMixin add an url relative to your page. Eg:

@route(r'^(\d+)/$')
def form_view(self, request, form_id=None):
    instance = get_object_or_404(MyModel, id=form_id)

(by xc0mallcaps)

參考文件

  1. Wagtail Django‑form edit existing object (CC BY‑SA 2.5/3.0/4.0)

#wagtail #django-forms #Django






相關問題

Wagtail Cms 是否支持 Google 登錄和用戶登錄添加會話 (Does Wagtail Cms support Google login and user login add session to)

Wagtail Django-form編輯現有對象 (Wagtail Django-form edit existing object)

如何將 Wagtail 'admin' 菜單添加到自定義模板? (How to add Wagtail 'admin' menu to custom templates?)

django.db.utils.OperationalError:外鍵不匹配 - “project_projectpage”引用“auth_user” (django.db.utils.OperationalError: foreign key mismatch - "project_projectpage" referencing "auth_user")

如何使用 Wagtail 鉤子在 Wagtail 中生成自定義鏈接 (How to generate a custom link in Wagtail using Wagtail hooks)

Wagtail:如何設置單元測試以進行簡單的頁面編輯? (Wagtail: How to setup up unittest for simple page edit?)

如何修復錯誤“str”對像沒有屬性“relative_url” (How to fix error 'str' object has no attribute 'relative_url')

如何將帖子從 Wordpress 導入 Wagtail 2(Draftail 編輯器),包括圖像? (How to import posts from Wordpress to Wagtail 2 (Draftail editor) including images?)

如何用外鍵鏈接兩種形式(wagtail 形式和 django 形式)? (How to link two forms (wagtail form and django form) with a foreign key?)

為什麼 RichText 不能在 wagtail 管理員中為帖子工作?這是發生的事情的類型:<h2>嘗試 post.content|richtext</h2> (Why is RichText not working in wagtail admin for posts? This is the type of thing that happens: <h2>Trying post.content|richtext</h2>)

Windows 10 上 wagtail 的客戶端文件夾在哪裡 (Where is the client folder of wagtail on windows 10)

過濾從 Wagtail 核心頁面導入的多個模型的自定義字段 (Filter on custom field across multiple models that import from Wagtail core Page)







留言討論